var i;
Object.defineProperty(exports, "__esModule", {
  value: true
});
var Module_Fighting_UIBindings = require("AA_Module_Fighting_UIBindings");
var EventManager = require("AA_EventManager");
var EvenType = require("AA_EvenType");
var Excel = require("AA_Excel");
var BaseModule = require("AA_BaseModule");
var GameDataManager = require("AA_GameDataManager");
var TipsManager = require("AA_TipsManager");
var BundleConfig = require("AA_BundleConfig");
var UIManager = require("AA_UIManager");
var UIConfig_Home = require("AA_UIConfig_Home");
var PlayerDataManager = require("AA_PlayerDataManager");
var UIRotate = require("AA_UIRotate");
var Const_Hall = require("AA_Const_Hall");
var HallGlobalVariable = require("AA_HallGlobalVariable");
var LogManager = require("AA_LogManager");
var UIConfig_Game = require("AA_UIConfig_Game");
var GameGlobalVariable = require("AA_GameGlobalVariable");
var ADManager = require("AA_ADManager");
var UI_BoxAward = require("AA_UI_BoxAward");
var AIControl = require("AA_AIControl");
var TTAPI = require("AA_TTAPI");
var _decorator = cc._decorator;
var _ccclass = _decorator.ccclass;
var _property = _decorator.property;

var _def_Module_Fighting = function (e) {
  function _creator() {
    var t = null !== e && e.apply(this, arguments) || this;
    t.auto_ui = null;
    t.qiehuanNode = null;
    t.boshuaward = null;
    t.awardNode = null;
    t.saodangLb = null;
    t.playicon = null;
    t.shaodanglb = null;
    t.kaishilb = null;
    t.zhangjieLb = null;
    t.nowviewid = 0;
    t.ismove = false;
    t.changId = 0;
    return t;
  }
  __extends(_creator, e);
  _creator.prototype.onEnable = function () {
    EventManager.EventMgr.addEventListener(EvenType.EVENT_TYPE.Game_Value_Fei, this.onFeiQian, this);
    EventManager.EventMgr.addEventListener(EvenType.EVENT_TYPE.Game_PASS, this.updateUi, this);
    this.onFeiQian();
    console.log('updateUi = 1111111111111');
    this.updateUi();
    this.AICheck();
    this.updateSaoDangUi();
    1 == HallGlobalVariable.default.selfMap["仓库引导升级完"] && (HallGlobalVariable.default.selfMap["仓库引导升级完"] = -1);
  };
  _creator.prototype.updateTiLi = function () {
    this.kaishilb.string = "×" + GameGlobalVariable.GameGlobalVariable.kaishitilicount;
    this.shaodanglb.string = "×" + GameGlobalVariable.GameGlobalVariable.shaodangtilicount;
  };
  _creator.prototype.updateSaoDangUi = function () {
    var e = PlayerDataManager.PlayerDataMgr.getSaoDangCount();
    if (e <= 0) {
      this.playicon.active = true;
      this.saodangLb.node.active = false;
    } else {
      this.playicon.active = false;
      this.saodangLb.node.active = true;
      this.saodangLb.string = "今日免费剩余" + e + "次";
    }
  };
  _creator.prototype.updateUi = function () {
    var e = GameDataManager.GameDataMgr.getNowMaxLevel();
    console.log('updateUi = ', e);
    if (0 == e) {
      this.setChangId(0);
    } else {
      this.setChangId(e);
    }
  };
  _creator.prototype.onFeiQian = function () {
    if (0 != GameGlobalVariable.GameGlobalVariable.adddimond) {
      EventManager.EventMgr.dispatchEvent(EvenType.EVENT_TYPE.Home_Add_Gold, 3, GameGlobalVariable.GameGlobalVariable.adddimond);
      GameGlobalVariable.GameGlobalVariable.adddimond = 0;
    }
    if (0 != GameGlobalVariable.GameGlobalVariable.addjinbi) {
      EventManager.EventMgr.dispatchEvent(EvenType.EVENT_TYPE.Home_Add_Gold, 2, GameGlobalVariable.GameGlobalVariable.addjinbi);
      GameGlobalVariable.GameGlobalVariable.addjinbi = 0;
    }
    if (0 != GameGlobalVariable.GameGlobalVariable.addpower) {
      EventManager.EventMgr.dispatchEvent(EvenType.EVENT_TYPE.Home_Add_Gold, 1, GameGlobalVariable.GameGlobalVariable.addpower);
      GameGlobalVariable.GameGlobalVariable.addpower = 0;
    }
  };
  _creator.prototype.onDisable = function () {
    EventManager.EventMgr.rmEventListener(EvenType.EVENT_TYPE.Game_Value_Fei, this.onFeiQian, this);
    EventManager.EventMgr.rmEventListener(EvenType.EVENT_TYPE.Game_PASS, this.updateUi, this);
  };
  _creator.prototype.show = function () {
    var e = this;
    this.auto_ui.addClickListener(this._clickListener, this);
    this.auto_ui.btn_sidebar.node.active = false;
    cc.sys.platform == cc.sys.BYTEDANCE_GAME && mg.checkScene({
      scene: "sidebar",
      success: function (t) {
        e.auto_ui.btn_sidebar.node.active = t.isExist;
      }
    });
    this.auto_ui.btn_rankBtn.node.active = false;
    cc.sys.platform == cc.sys.BYTEDANCE_GAME && (this.auto_ui.btn_rankBtn.node.active = true);
  };
  _creator.prototype.hide = function () { };
  _creator.prototype._clickListener = function (e) {
    var t = this;
    var o = this.auto_ui;
    switch (e) {
      case o.btn_saodang:
        if (PlayerDataManager.PlayerDataMgr.globalData.power >= GameGlobalVariable.GameGlobalVariable.shaodangtilicount) {
          if (PlayerDataManager.PlayerDataMgr.getSaoDangCount() > 0) {
            PlayerDataManager.PlayerDataMgr.SubPower(GameGlobalVariable.GameGlobalVariable.shaodangtilicount);
            PlayerDataManager.PlayerDataMgr.subSaoDangCount(1);
            this.updateSaoDangUi();
            GameGlobalVariable.GameGlobalVariable.nowlevel = this.changId + 1;
            UIManager.default.open(BundleConfig.BundleNames.Game, UIConfig_Game.UIView_Game.UI_GameOver, {
              type: 2,
              back: function () { }
            });
          } else {
            ADManager.ADMgr.showRewardedVideo("视频扫荡", function () {
              PlayerDataManager.PlayerDataMgr.SubPower(GameGlobalVariable.GameGlobalVariable.shaodangtilicount);
              GameGlobalVariable.GameGlobalVariable.nowlevel = t.changId + 1;
              UIManager.default.open(BundleConfig.BundleNames.Game, UIConfig_Game.UIView_Game.UI_GameOver, {
                type: 2,
                back: function () { }
              });
            });
          }
        } else {
          TipsManager.TipMgr.showToast("体力不足");
        }
        break;
      case o.btn_startgame:
        this.onClickStartGame();
        break;
      case o.btn_setting:
        this.showSetting();
        break;
      case o.btn_qiandao:
        this.showQianDao();
        break;
      case o.btn_sidebar:
        UIManager.default.open(BundleConfig.BundleNames.Home, UIConfig_Home.UIView_Home.UI_Sidebar);
        break;
      case o.btn_rankBtn:
        cc.sys.platform == cc.sys.BYTEDANCE_GAME && TTAPI.default.getImRankList();
    }
  };
  _creator.prototype.showQianDao = function () {
    UIManager.default.open(BundleConfig.BundleNames.Home, UIConfig_Home.UIView_Home.UI_QianDao);
  };
  _creator.prototype.showSetting = function () {
    UIManager.default.open(BundleConfig.BundleNames.Home, UIConfig_Home.UIView_Home.UI_Setting);
  };
  _creator.prototype.onClickStartGame = function () {
    if (PlayerDataManager.PlayerDataMgr.dressUpArray.every(function (e) {
      return 0 != e;
    })) {
      var e = Excel.Excel.shuiguoguanqia(this.changId + 1);
      var t = GameDataManager.GameDataMgr.getNowLevelPassState(e.id, 2);
      if (1 == t || 2 == t) {
        EventManager.EventMgr.dispatchEvent(EvenType.EVENT_TYPE.Hall_StartGame, this.changId + 1);
      } else {
        TipsManager.TipMgr.showToast("暂未解锁");
      }
    } else {
      TipsManager.TipMgr.showToast("背包中有空位未上阵水果");
    }
  };
  _creator.prototype.setNowView = function (e) {
    var t = this;
    var o = this.qiehuanNode.children[this.nowviewid];
    var n = null;
    n = 0 == this.nowviewid ? this.qiehuanNode.children[1] : this.qiehuanNode.children[0];
    this.ismove = true;
    if (1 == e) {
      cc.tween(o).to(.25, {
        x: 375 + o.width
      }).start();
      n.x = -(375 + n.width);
      cc.tween(n).to(.25, {
        x: 0
      }).call(function () {
        t.ismove = false;
      }).start();
    } else {
      cc.tween(o).to(.25, {
        x: -(375 + o.width)
      }).start();
      n.x = 375 + n.width;
      cc.tween(n).to(.25, {
        x: 0
      }).call(function () {
        t.ismove = false;
      }).start();
    }
    if (0 == this.nowviewid) {
      this.nowviewid = 1;
    } else {
      this.nowviewid = 0;
    }
    var i = GameDataManager.GameDataMgr.getNowMaxLevel() + GameGlobalVariable.GameGlobalVariable.houlevelunlock;
    var a = Excel.Excel.shuiguoguanqia_all.size;
    i > a && (i = a);
    this.auto_ui.node_rightNode.active = true;
    this.auto_ui.node_leftNode.active = true;
    this.changId + 1 > i - 1 && (this.auto_ui.node_rightNode.active = false);
    this.changId - 1 < 0 && (this.auto_ui.node_leftNode.active = false);
    console.log('111111111111111')
    this.updateRenData();
  };
  _creator.prototype.updateRenData = function () {
    return __awaiter(this, undefined, undefined, function () {
      var e;
      var t;
      var o;
      var n;
      var i;
      var a;
      var r;
      var c;
      var u;
      var l;
      return __generator(this, function (s) {
        switch (s.label) {
          case 0:
            e = Excel.Excel.shuiguoguanqia(this.changId + 1);
            t = GameDataManager.GameDataMgr.nowLevelData(this.changId + 1);
            LogManager.LogMgr.debug("当前关卡本地数据", t);
            o = this.qiehuanNode.children[this.nowviewid];
            return [4, this._loadRes(BundleConfig.BundleNames.Home, "home/" + "res/初始之地/levelicon" + e.dipicture, cc.SpriteFrame)];
          case 1:
            n = s.sent();
            o.getComponent(cc.Sprite).spriteFrame = n;
            o.children[0].getComponent(cc.Sprite).spriteFrame = n;
            this.auto_ui.txt_title.string = e.id + "." + e.levelname;
            switch (GameDataManager.GameDataMgr.getNowLevelPassState(e.id, 2)) {
              case -1:
                this.auto_ui.btn_startgame.node.active = false;
                this.auto_ui.txt_zhangjielb.node.active = true;
                this.auto_ui.txt_zhangjielb.string = "通过第" + this.changId + "章节解锁";
                this.auto_ui.txt_levelstate.string = "未解锁";
                this.auto_ui.btn_saodang.node.active = false;
                o.children[0].active = true;
                break;
              case 1:
                this.auto_ui.txt_zhangjielb.node.active = false;
                this.auto_ui.btn_startgame.node.active = true;
                this.auto_ui.txt_levelstate.string = "已通关";
                this.auto_ui.btn_saodang.node.active = true;
                o.children[0].active = false;
                break;
              case 2:
                this.auto_ui.btn_startgame.node.active = true;
                this.auto_ui.txt_zhangjielb.node.active = false;
                this.auto_ui.txt_levelstate.string = "最高纪录:" + GameDataManager.GameDataMgr.getMaxLevelBoshuState(this.changId + 1, 2) + "/" + e.levelboshuid.length;
                this.auto_ui.btn_saodang.node.active = false;
                o.children[0].active = false;
            }
            i = this.boshuaward.children;
            for (l = 0; l < i.length; l++) {
              a = i[l];
              r = e.awardboshuid[l];
              a.children[1].getComponent(cc.Label).string = "第" + r + "波";
              if (GameDataManager.GameDataMgr.getMaxLevelBoshuState(this.changId + 1, 2) >= r) {
                if (GameDataManager.GameDataMgr.getLevelAwardJilu(this.changId + 1, r)) {
                  a.children[0].getChildByName("unlockimg").active = true;
                  a.children[0].getChildByName("lockimg").active = false;
                  a.children[0].getChildByName("redpoint").active = false;
                  a.children[0].getComponent(UIRotate.default).stopRotate();
                } else {
                  a.children[0].getChildByName("unlockimg").active = false;
                  a.children[0].getChildByName("lockimg").active = true;
                  a.children[0].getChildByName("redpoint").active = true;
                  a.children[0].getComponent(UIRotate.default).startRotate();
                }
              } else {
                a.children[0].getChildByName("unlockimg").active = false;
                a.children[0].getChildByName("lockimg").active = true;
                a.children[0].getChildByName("redpoint").active = false;
                a.children[0].getComponent(UIRotate.default).stopRotate();
              }
            }
            c = false;
            for (l = this.changId; l >= 0; l--) {
              GameDataManager.GameDataMgr.getLevelAwardHave(l) && (c = true);
            }
            this.auto_ui.node_leftNode.getChildByName("redpoint").active = c;
            u = false;
            for (l = this.changId + 2; l < Excel.Excel.shuiguoguanqia_all.size; l++) {
              GameDataManager.GameDataMgr.getLevelAwardHave(l) && (u = true);
            }
            this.auto_ui.node_rightNode.getChildByName("redpoint").active = u;
            return [2];
        }
      });
    });
  };
  _creator.prototype.onAwardBoxClick = function (e, t) {
    var o = Excel.Excel.shuiguoguanqia(this.changId + 1);
    var n = o.awardboshuid[Number(t) - 1];
    if (GameDataManager.GameDataMgr.getMaxLevelBoshuState(this.changId + 1, 2) >= n) {
      if (GameDataManager.GameDataMgr.getLevelAwardJilu(this.changId + 1, n)) {
        TipsManager.TipMgr.showToast("已领取");
      } else {
        TipsManager.TipMgr.showToast("恭喜获得奖励");
        switch (t) {
          case "1":
            this.getAwardData(o.awardbox1);
            break;
          case "2":
            this.getAwardData(o.awardbox2);
            break;
          case "3":
            this.getAwardData(o.awardbox3);
        }
        GameDataManager.GameDataMgr.unLevelAwardJiLu(this.changId + 1, n);
        console.log('222222222222222222')
        this.updateRenData();
      }
    } else {
      var i = e.getCurrentTarget();
      this.awardNode.getComponent(UI_BoxAward.default).showAward(i, o, t);
    }
  };
  _creator.prototype.onHideAwradTip = function () {
    this.awardNode.active && (this.awardNode.active = false);
  };
  _creator.prototype.getAwardData = function (e) {
    var t = new Const_Hall.GetItemsData();
    t.ids = [];
    t.counts = [];
    for (var o = 0; o < e.length; o++) {
      var n = e[o];
      switch (n[0]) {
        case 1:
          t.ids.push(HallGlobalVariable.default.goldId);
          t.counts.push(n[1]);
          break;
        case 2:
          t.ids.push(HallGlobalVariable.default.diamondId);
          t.counts.push(n[1]);
          break;
        case 3:
          t.ids.push(HallGlobalVariable.default.powerId);
          t.counts.push(n[1]);
          break;
        case 5:
          var i = null;
          1 == n[1] && (i = HallGlobalVariable.default.GetSuiPian([n[2], 0, 0]));
          2 == n[1] && (i = HallGlobalVariable.default.GetSuiPian([0, n[2], 0]));
          3 == n[1] && (i = HallGlobalVariable.default.GetSuiPian([0, 0, n[2]]));
          i.forEach(function (e, o) {
            t.ids.push(o);
            t.counts.push(e);
          });
      }
    }
    t.clickCallBack = function () {
      for (var e = 0; e < t.ids.length; e++) {
        var o = t.ids[e];
        var n = t.counts[e];
        switch (o) {
          case HallGlobalVariable.default.goldId:
            EventManager.EventMgr.dispatchEvent(EvenType.EVENT_TYPE.Home_Add_Gold, 2, n);
            break;
          case HallGlobalVariable.default.diamondId:
            EventManager.EventMgr.dispatchEvent(EvenType.EVENT_TYPE.Home_Add_Gold, 3, n);
            break;
          case HallGlobalVariable.default.powerId:
            EventManager.EventMgr.dispatchEvent(EvenType.EVENT_TYPE.Home_Add_Gold, 1, n);
            break;
          default:
            TipsManager.TipMgr.showToast("恭喜获得水果碎片");
            PlayerDataManager.PlayerDataMgr.AddEquipFragments(o, n);
        }
      }
    };
    UIManager.default.open(BundleConfig.BundleNames.Home, UIConfig_Home.UIView_Home.UI_GetItems, t);
  };
  _creator.prototype.setChangId = function (e) {
    this.changId = e;
    this.auto_ui.node_rightNode.active = true;
    this.auto_ui.node_leftNode.active = true;
    this.qiehuanNode.children[this.nowviewid];
    console.log('3333333333333333333')
    this.updateRenData();
    var t = GameDataManager.GameDataMgr.getNowMaxLevel() + GameGlobalVariable.GameGlobalVariable.houlevelunlock;
    var o = Excel.Excel.shuiguoguanqia_all.size;
    t > o && (t = o);
    this.changId + 1 > t - 1 && (this.auto_ui.node_rightNode.active = false);
    this.changId - 1 < 0 && (this.auto_ui.node_leftNode.active = false);
  };
  _creator.prototype.nextLevel = function () {
    if (!this.ismove) {
      this.changId += 1;
      this.setNowView(2);
    }
  };
  _creator.prototype.lastLevel = function () {
    if (!this.ismove) {
      this.changId -= 1;
      this.setNowView(1);
    }
  };
  _creator.prototype.AICheck = function () {
    if (AIControl.default._instance.isOpen) {
      var e = this;
      AIControl.default._instance.ShowClickBtn(this.auto_ui.btn_startgame.node, function () {
        e.onClickStartGame();
      });
    }
  };
  __decorate([_property(Module_Fighting_UIBindings.default)], _creator.prototype, "auto_ui", undefined);
  __decorate([_property(cc.Node)], _creator.prototype, "qiehuanNode", undefined);
  __decorate([_property(cc.Node)], _creator.prototype, "boshuaward", undefined);
  __decorate([_property(cc.Node)], _creator.prototype, "awardNode", undefined);
  __decorate([_property(cc.Label)], _creator.prototype, "saodangLb", undefined);
  __decorate([_property(cc.Node)], _creator.prototype, "playicon", undefined);
  __decorate([_property(cc.Label)], _creator.prototype, "shaodanglb", undefined);
  __decorate([_property(cc.Label)], _creator.prototype, "kaishilb", undefined);
  __decorate([_property(cc.Label)], _creator.prototype, "zhangjieLb", undefined);
  return __decorate([_ccclass], _creator);
}(BaseModule.default);
exports.default = _def_Module_Fighting;